/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package sv.com.bolsaTrabajo.model.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author sysmanager
 */
@Entity
@Table(name = "idioma_persona", catalog = "bolsadetrabajo", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "IdiomaPersona.findAll", query = "SELECT i FROM IdiomaPersona i"),
    @NamedQuery(name = "IdiomaPersona.findByIdIdioma", query = "SELECT i FROM IdiomaPersona i WHERE i.idiomaPersonaPK.idIdioma = :idIdioma"),
    @NamedQuery(name = "IdiomaPersona.findByIdPersona", query = "SELECT i FROM IdiomaPersona i WHERE i.idiomaPersonaPK.idPersona = :idPersona"),
    @NamedQuery(name = "IdiomaPersona.findByPorcentaje", query = "SELECT i FROM IdiomaPersona i WHERE i.porcentaje = :porcentaje")})
public class IdiomaPersona implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected IdiomaPersonaPK idiomaPersonaPK;
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false)
    private int porcentaje;
    @JoinColumn(name = "id_idioma", referencedColumnName = "id_idioma", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Idioma idioma;
    @JoinColumn(name = "id_persona", referencedColumnName = "id_persona", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Persona persona;

    public IdiomaPersona() {
    }

    public IdiomaPersona(IdiomaPersonaPK idiomaPersonaPK) {
        this.idiomaPersonaPK = idiomaPersonaPK;
    }

    public IdiomaPersona(IdiomaPersonaPK idiomaPersonaPK, int porcentaje) {
        this.idiomaPersonaPK = idiomaPersonaPK;
        this.porcentaje = porcentaje;
    }

    public IdiomaPersona(int idIdioma, int idPersona) {
        this.idiomaPersonaPK = new IdiomaPersonaPK(idIdioma, idPersona);
    }

    public IdiomaPersonaPK getIdiomaPersonaPK() {
        return idiomaPersonaPK;
    }

    public void setIdiomaPersonaPK(IdiomaPersonaPK idiomaPersonaPK) {
        this.idiomaPersonaPK = idiomaPersonaPK;
    }

    public int getPorcentaje() {
        return porcentaje;
    }

    public void setPorcentaje(int porcentaje) {
        this.porcentaje = porcentaje;
    }

    public Idioma getIdioma() {
        return idioma;
    }

    public void setIdioma(Idioma idioma) {
        this.idioma = idioma;
    }

    public Persona getPersona() {
        return persona;
    }

    public void setPersona(Persona persona) {
        this.persona = persona;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idiomaPersonaPK != null ? idiomaPersonaPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof IdiomaPersona)) {
            return false;
        }
        IdiomaPersona other = (IdiomaPersona) object;
        if ((this.idiomaPersonaPK == null && other.idiomaPersonaPK != null) || (this.idiomaPersonaPK != null && !this.idiomaPersonaPK.equals(other.idiomaPersonaPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "sv.com.bolsaTrabajo.controller.IdiomaPersona[ idiomaPersonaPK=" + idiomaPersonaPK + " ]";
    }
    
}
